﻿using System;
using InterfaceLiftLib.Models.Enums;
using Newtonsoft.Json;

namespace InterfaceLiftLib.Converters.Json
{
    public class TagTypeConverter : JsonConverter
    {
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            throw new NotImplementedException();
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var stringValue = reader.Value as String;
            TagType type = TagType.Unknown;
            Enum.TryParse(stringValue, out type);
            return type;
        }

        public override bool CanConvert(Type objectType)
        {
            return objectType == typeof(string);
        }
    }
}
